<template>
  <div class="content-box">
    <nav-title title="资格证书" />
    <div class="line">
      <span class="important">*</span>
      <div class="label">名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="qualty.cName">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">等级</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="qualty.cLevel">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">签发单位</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="qualty.cCompany">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">签发日期</div>
      <div class="value">
        <group>
          <datetime :min-year="1900" :max-year="2100" value-text-align="left" placeholder="请选择" v-model="qualty.cDate"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">有效期</div>
      <div class="value">
        <group>
          <datetime :min-year="1900" :max-year="2100" value-text-align="left" placeholder="请选择" v-model="qualty.cDate1"></datetime>
        </group>
      </div>
    </div>
    <div class="submit-btn" @click="save">
      保存
    </div>
    <div class="remove-btn" @click="remove">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { saveQualification,delQualification,getDicItem } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  data() {
    return {
    qualty:{
      rsHireId: '',
    },
    qualDel:{
      rsHireId: '',
      cSeqno: ''
    },

    }
  },
  created() {
    this.getQal()
    if(this.$store.state.hid){
      this.qualty.rsHireId = this.$store.state.hid
      this.qualDel.rsHireId = this.$store.state.hid
    }
  },
  methods: {
    save() {
      const that = this
      if(that.qualty.cName == undefined || that.qualty.cName == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入名称'
        });
        return;
      }
      if(that.qualty.cDate == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择签发日期'
        });
        return;
      }

      saveQualification(json2Form(this.qualty)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {

      const _this = this;
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delQualification(json2Form(_this.qualDel)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                _this.$vux.alert.show({
                  title: '提示',
                  content: '删除成功',
                  onHide () {
                    _this.$router.push('/informationCollection/userInfo');
                  }
                })
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })

            
          }
        })
    },
    getQal() {
      if(this.$route.params.qualt){
        this.qualty = this.$route.params.qualt
        this.qualDel.cSeqno = this.$route.params.qualt.cSeqno
        console.log(this.qualty)
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
